package com.wuyou.mid;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 1333. 餐厅过滤器
 *
 * @Description
 * @Author 无忧
 * @Date 2023/9/27 21:21
 */
public class FilterRestaurants {


    public static void main(String[] args) {
        int[][] restaurants = {{1, 4, 1, 40, 10}, {2, 8, 0, 50, 5}, {3, 8, 1, 30, 4}, {4, 10, 0, 10, 3}, {5, 1, 1, 15, 1}};
        int veganFriendly = 1;
        int maxPrice = 50;
        int maxDistance = 10;

        System.out.println(solution(restaurants, veganFriendly, maxPrice, maxDistance));
    }

    public static List<Integer> solution(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {
        List<int[]> ans = new ArrayList<>();
        for (int i = 0; i < restaurants.length; i++) {
            if (veganFriendly == 1 && restaurants[i][2] != 1) {
                continue;
            }
            if (maxPrice < restaurants[i][3]) {
                continue;
            }
            if (maxDistance < restaurants[i][4]) {
                continue;
            }
            int[] tempArr = {restaurants[i][0], restaurants[i][1]};
            ans.add(tempArr);
        }
        return ans.stream().sorted(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o2[1] == o1[1]) {
                    return o2[0] - o1[0];
                }
                return o2[1] - o1[1];
            }
        }).map(e -> e[0]).collect(Collectors.toList());

    }
}
